#include "fig_player_craft.h"
#include "fig_sounds.h"


FIGPlayerCraft::Armor::Armor()   :	m_Counter(0),
									m_Rotation(0)
{
	m_BlinkCounter.SetLimit(0.1f);
	m_Sprite.Create("player_cover");	
}

void	FIGPlayerCraft::Armor::Tick(float dt)
{
	m_Sprite.Tick(dt);
	if(m_Counter > 0)
	{
		m_Counter -= dt;
		m_Rotation -= (120 * dt);
		if(m_Rotation < 0.0f)
			m_Rotation += 360.0f;
		if(m_Counter < 2.0f)
		{
			m_BlinkCounter.Tick(dt);
			if(m_BlinkCounter.IsReady())
				m_BlinkCounter.Reset();
		}

		if(m_Counter <= 0)
		{
			FIGSounds::Instance().PlaySoundSFX(FIGSounds::SHIELD_OFF);
		}
	} 
}

void	FIGPlayerCraft::Armor::Render(const math::Vec2& Offset,
									  const math::Vec2& ShipPos,
									  float Scale)
{
	if(m_Counter > 0)
	{
		if(m_Counter < 2.0f && 
           m_BlinkCounter.GetProgress() < 0.3f)
		{}
		else
		{
			m_Sprite.m_Pos = ShipPos + Offset + math::Vec2(0,0.005f);
			m_Sprite.m_Rotation = m_Rotation;
			m_Sprite.m_Size = m_Sprite.m_SizeOriginal * Scale;      		
			m_Sprite.m_Color = ColorfRGBA(1.0f,1.0f,1.0f,0.7f);
			m_Sprite.RenderRotated();
		}
	}
}

void	FIGPlayerCraft::Armor::Activate()
{
	m_Counter = ARMOR_MAX_COUNTER;
}

bool	FIGPlayerCraft::Armor::IsActivating()const
{
	if(m_Counter <= 0)
		return false;

	return true;
}

